package com.carlinfo.stu_ques.demo.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.carlinfo.stu_ques.demo.dao.IDynastyDao;
import com.carlinfo.stu_ques.demo.dao.Iking;
import com.carlinfo.stu_ques.demo.pojo.Dynasty;
import com.carlinfo.stu_ques.demo.pojo.King;
import com.carlinfo.stu_ques.demo.service.IDemoService;

public class DemoServiceImpl implements IDemoService
{
	private IDynastyDao dynasty ;
	private Iking king ;
	
	
	@Override
	public int savaOneDynastyService(Dynasty dynasty)
	{
		int id  = this.dynasty.savaOneDao(dynasty);
		return id;
	}

	@Override
	public void deleteOneDynastyService(Dynasty dynasty)
	{
		this.dynasty.deleteOneDao(dynasty);
	}

	@Override
	public void updateOneDynastyService(Dynasty dynasty)
	{
		this.dynasty.updateOneDao(dynasty);
	}

	@Override
	public List<Dynasty> selectListDynastyService()
	{
		List<Dynasty> list = this.dynasty.selectListDao();
		return list;
	}

	@Override
	public Dynasty selectOneDynastyService(Map<String, Object> condMap)
	{
		return this.dynasty.selectOneDao(condMap);
	}

	@Override
	public String printTitleDynastyService()
	{
		String rulet  = "id\t名字\t首都\t年龄\t开国时间\t\t\t创建时间\t\t\t更新时间";
		return rulet;
	}

	@Override
	public int savaOneKingService(King king)
	{
		this.king.savaOneDao(king);
		return 0;
	}

	@Override
	public void deleteOneKingService(King king)
	{
		this.king.deleteOneDao(king);
	}

	@Override
	public void updateOneKingService(King king)
	{
		this.king.updateOneDao(king);
	}

	@Override
	public List<King> selectListKingService()
	{
		
		List<King> list =  this.king.selectListDao();
		
		Map<String, Object> untMap = new HashMap<String, Object>();
		for (King king : list)
		{
			int id = (int) king.getDynastyId();
			untMap.put("id", id);
			Dynasty dynasty = this.selectOneDynastyService(untMap);
			king.setdynasty(dynasty);
		}
		return list;
	}

	@Override
	public King selectOneKingService(Map<String, Object> condMap)
	{
		return this.king.selectOneDao(condMap);
	}

	@Override
	public String printTitleKingService()
	{
		String result = "id\t朝代Id\t名字\t年龄\t身高\t庙号\t年号\t创建时间\t\t\t更新时间";
		return result;
	}

	public void setDynasty(IDynastyDao dynasty)
	{
		this.dynasty = dynasty;
	}

	public void setKing(Iking king)
	{
		this.king = king;
	}

}
